home *** CD-ROM | disk | FTP | other *** search
- Path: newshub.cts.com!usenet
- From: lboard@cts.com (Larry Board)
- Newsgroups: comp.lang.c++
- Subject: Re: What is referencing good for?
- Date: Sun, 25 Feb 1996 20:22:41 GMT
- Organization: CTS Network Services
- Message-ID: <3130c026.8571250@news2.cts.com>
- References: <4goojd$a9g@wintermute.ecs.fullerton.edu> <4goutn$31u@news.bridge.net>
- NNTP-Posting-Host: lboard.cts.com
-
- On 25 Feb 1996 06:17:27 GMT, David Byrden <100101.2547@compuserve.com>
- wrote:
-
- >
- >
- >
- > Gil;
- >
- >
- >>> Can someone give me a REAL world example of where I would use
- >>> referencing perhaps somewhere that I can not use pointers?
- >
- >
- > References are necessary to allow operator overloading.
- >Consider this;
- >
- >
- >class array {
- >private:
- > int * dataBlock ;
- >public :
- > int& operator[] ( int index )
- > {
- > return dataBlock [ index ] ;
- > }
- > // constructor etc etc
- >} ;
- >
- >
- >
- > array ar ;
- > ar[4] = 0 ; // can't be done with pointers
- >
- >
-
- Good example, but.... the next question begs to be answered. Why
- would anybody want to do this? It essentially gives public access to
- datablock, which is a private variable.
-
-
-